package br.inf.solutions.apresentacoes.ssp.control.bulletin;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import br.com.vexillum.util.Return;
import br.inf.solutions.apresentacoes.ssp.model.bulletin.BulletinAwaitItens;
import br.inf.solutions.apresentacoes.ssp.model.bulletin.BulletinTopics;
import br.inf.solutions.apresentacoes.ssp.model.interfaces.IBulletinItem;

@Service
@Scope("prototype")
public class BulletinAwaitItensController extends BaseBulletinController<BulletinAwaitItens> {

	public BulletinAwaitItensController() {
		super(BulletinAwaitItens.class);
	}
	
	public Return searchByTopic(){
		BulletinTopics topic = (BulletinTopics) data.get("topic");
		String sql = "FROM BulletinAwaitItens WHERE topic = " + topic.getId() + " AND item.publication = " + getAwaitingPublication().getId();
		data.put("sql", sql);
		return searchByHQL();
	}
	
	public Return getAllAwaitingItens(){
		String sql = "FROM BulletinAwaitItens WHERE item.publication = " + getAwaitingPublication().getId();
		data.put("sql", sql);
		return searchByHQL();
	}
	
	public Return getAllAwaitingItens(IBulletinItem item){
		String sql = "FROM BulletinAwaitItens WHERE item.publication = " + getAwaitingPublication().getId() + "";
		data.put("sql", sql);
		return searchByHQL();
	}
	
	public Return getAllNotPublishItens(){
		String sql = "FROM BulletinAwaitItens WHERE item.publication = " + getNotPublishedPublication().getId();
		data.put("sql", sql);
		return searchByHQL();
	}

	public Return notPublishItem(){
		Return ret = new Return(true);
		
		BulletinAwaitItens item = getEntity();
		item.getItem().setPublication(getNotPublishedPublication());
		
		return ret;
	}
	
	public Return deleteItem(){
		Return ret = new Return(true);
		
		ret.concat(delete());
		ret.concat(deleteBulletinItem(getEntity().getItem()));
		
		return ret;
	}
	
	public Return realocate(){
		Return ret = new Return(true);
		
		BulletinAwaitItens item = getEntity();
		item.getItem().setPublication(getAwaitingPublication());
		
		return ret;
	}
	
}
